import { FGTeamInfo } from "./FGTeamInfo";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { ClockManager } from "../../manager/ClockManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { _teamInfo } from "../../../../this/_teamInfo";
type int = number;
//class FGFourSelectPanel
    
    export  class FGFourSelectPanel /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._radioArray = [];
            this.init();
            return;
        }

        public updateByGameInfo(arg1: FGTeamInfo): void
        {
            var loc2=null;
            var loc3=0;
            var loc4=0;
            var loc1=arg1.gameInfo;
            if (loc1) 
            {
                loc4 = 0;
                while (loc4 < this._radioArray.length) 
                {
                    loc2 = this._radioArray[loc4] as GCheckBox;
                    loc3 = int(loc2.name);
                    arg1 = Cache.instance.footballGuess.gameInfoDict["4-" + (loc3 + 1)];
                    if (loc1.guess == arg1.gameInfo.result) 
                    {
                        this.selectByIndex(loc3);
                    }
                    if (!(arg1.gameInfo.result == loc1.teamA) && !(arg1.gameInfo.result == loc1.teamB)) 
                    {
                        loc2.visible = false;
                    }
                    loc2.enabled = this.isCanGuess();
                    ++loc4;
                }
            }
            return;
        }

        /* internal  */init(): void
        {
            var loc2=0;
            var loc3=0;
            var loc4=null;
            var loc5=null;
            var loc1=[{"x": 0, "y": 0}, {"x": 0, "y": 175}, {"x": 300, "y": 0}, {"x": 300, "y": 175}];
            var loc6=0;
            while (loc6 < loc1.length) 
            {
                loc2 = (loc4 = loc1[loc6]).x;
                loc3 = loc4.y;
                (loc5 = ObjCreate.createCheckBox("", loc2, loc3, 20, 20, this, "GCheckBox")).name = loc6.toString();
                loc5.addEventListener(flash.events.MouseEvent.CLICK, this.onSelectChangeHandler);
                this._radioArray.push(loc5);
                ++loc6;
            }
            return;
        }

        /* internal  */isCanGuess(): Boolean
        {
            var loc1=ClockManager.instance.nowDate;
            return loc1.month == 6 && loc1.date == 1;
        }

        /* internal  */onSelectChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc2=false;
            var loc1=int((arg1.target as GCheckBox).name);
            this._teamInfo = Cache.instance.footballGuess.gameInfoDict["4-" + (loc1 + 1)];
            if (this._teamInfo) 
            {
                if (this._teamInfo.gameInfo.result != this._teamInfo.gameInfo.teamA) 
                {
                    loc2 = false;
                }
                else 
                {
                    loc2 = true;
                }
                this.selectByIndex(loc1);
                Dispatcher.dispatchEvent(new DataEvent(EventName.FootballGuessAlertWindowOpen, {"teamInfo": _teamInfo, "isA": loc2, "clickFun": this.onAlertClickHander}));
            }
            return;
        }

        /* internal  */onAlertClickHander(arg1: Boolean): void
        {
            if (!arg1) 
            {
                this.selectByIndex(-1);
            }
            return;
        }

        /* internal  */selectByIndex(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            while (loc3 < this._radioArray.length) 
            {
                loc1 = this._radioArray[loc3] as GCheckBox;
                loc2 = int(loc1.name);
                if (loc2 != arg1) 
                {
                    loc1.selected = false;
                }
                else 
                {
                    loc1.selected = true;
                }
                ++loc3;
            }
            return;
        }

        public enableSelect(arg1: Boolean): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._radioArray.length) 
            {
                loc1 = this._radioArray[loc2] as GCheckBox;
                loc1.enabled = arg1;
                ++loc2;
            }
            return;
        }

        /* internal */ /* var */_radioArray: Array<any>;

        /* internal */ /* var */_teamInfo: FGTeamInfo;
    }
